﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Odbc;
using System.Drawing;
using System.Data;

namespace SONORA2012
{
	public partial class SYS_TABLE_EDITOR : System.Web.UI.Page
	{
		SNRDB iSNRDB = new SNRDB();
		
		string tableName = null;
		string tableDescription = null;
		string ODBCConnStr = null;
		string ODBCCommands = null;
		string dbDSNName = "SNRDB";
		string dbUserName = "PROGRAMMER";
		string dbUserPassword = "apr";

		private bool ConnectToODBC( out string MSG)
		{
			MSG = null;

			ODBCConnStr = "Dsn=" + dbDSNName + ";uid=" + dbUserName + ";pwd=" + dbUserPassword;
			OdbcConnection newODBCConn = new OdbcConnection(ODBCConnStr);
			try
			{
				newODBCConn.Open();
				MSG = "Giriş yapıldı.";
			}
			catch
			{
				MSG = "Kullanıcı bilgileri hatalı!";
				return false;
			}
			
			return true;
		}

		private Dictionary<string, string> GetTableList()
		{
			string MSG = null;
			
			Dictionary<string, string> TableList = new Dictionary<string, string>();

			if (ConnectToODBC(out MSG))
			{
				lblStatus.ForeColor = Color.Green;
				lblStatus.Text = MSG;

				ODBCCommands = "select * from SYS_TABLE order by TABLE_NAME";
			}
			else
			{
				lblStatus.ForeColor = Color.Red;
				lblStatus.Text = MSG;
			}
			
			//var iTempPath = from Template in TemplateInfo.XML.Descendants("Page")
			//                select Template;
			//foreach (XElement Item in iTempPath)
			//{
			//    TemplateList.Add(Item.Attribute("Name").Value, Item.Attribute("StructurePath").Value);
			//}

			return TableList;
		}
		
		protected void Page_Load(object sender, EventArgs e)
		{
			//ODBCConnStr = "Dsn=SNRDB;uid=PROGRAMMER;pwd=apr";
			//OdbcConnection newODBCConn = new OdbcConnection(ODBCConnStr);
			//try
			//{
			//    newODBCConn.Open();
			//    lblStatus.ForeColor = Color.Green;
			//    lblStatus.Text = "Giriş yapıldı.";
			//}
			//catch
			//{
			//    lblStatus.ForeColor = Color.Red;
			//    lblStatus.Text = "Kullanıcı bilgileri hatalı!";
			//}
		}

		protected void btnSave_Click(object sender, EventArgs e)
		{
			tableName = txtTableName.Text;
			tableDescription = txtTableDesc.Text;

			
		}

		protected void btnSaveTable_Click(object sender, EventArgs e)
		{
			
		}

		protected void Button1_Click(object sender, EventArgs e)
		{
			SNRDB.SNRTable newSNRTable = new SNRDB.SNRTable("DEF_YESNO");
		}
	}
}